/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.wins.vertx.entity;

import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

/**
 * Converter for {@link io.wins.vertx.entity.Concert}.
 *
 * NOTE: This class has been automatically generated from the {@link io.wins.vertx.entity.Concert} original class using Vert.x codegen.
 */
public class ConcertConverter {

  public static void fromJson(final JsonObject json, final Concert obj) {
    if (json.getValue("beginOn") instanceof String) {
      obj.setBeginOn((String)json.getValue("beginOn"));
    }
    if (json.getValue("concertTime") instanceof JsonArray) {
      final java.util.ArrayList<io.wins.vertx.entity.ConcertTime> list = new java.util.ArrayList<>();
      json.getJsonArray("concertTime").forEach( item -> {
        if (item instanceof JsonObject)
          list.add(new io.wins.vertx.entity.ConcertTime((JsonObject)item));
      });
      obj.setConcertTime(list);
    }
    if (json.getValue("content") instanceof String) {
      obj.setContent((String)json.getValue("content"));
    }
    if (json.getValue("createdOn") instanceof Number) {
      obj.setCreatedOn(((Number)json.getValue("createdOn")).longValue());
    }
    if (json.getValue("faceValues") instanceof JsonArray) {
      final java.util.ArrayList<io.wins.vertx.entity.FaceValues> list = new java.util.ArrayList<>();
      json.getJsonArray("faceValues").forEach( item -> {
        if (item instanceof JsonObject)
          list.add(new io.wins.vertx.entity.FaceValues((JsonObject)item));
      });
      obj.setFaceValues(list);
    }
    if (json.getValue("minPrice") instanceof Number) {
      obj.setMinPrice(((Number)json.getValue("minPrice")).floatValue());
    }
    if (json.getValue("place") instanceof String) {
      obj.setPlace((String)json.getValue("place"));
    }
    if (json.getValue("poster") instanceof String) {
      obj.setPoster((String)json.getValue("poster"));
    }
    if (json.getValue("score") instanceof Number) {
      obj.setScore(((Number)json.getValue("score")).floatValue());
    }
    if (json.getValue("seatMapId") instanceof String) {
      obj.setSeatMapId((String)json.getValue("seatMapId"));
    }
    if (json.getValue("seatType") instanceof String) {
      obj.setSeatType((String)json.getValue("seatType"));
    }
    if (json.getValue("seats") instanceof String) {
      obj.setSeats((String)json.getValue("seats"));
    }
    if (json.getValue("shortDesc") instanceof String) {
      obj.setShortDesc((String)json.getValue("shortDesc"));
    }
    if (json.getValue("status") instanceof String) {
      obj.setStatus((String)json.getValue("status"));
    }
    if (json.getValue("tags") instanceof String) {
      obj.setTags((String)json.getValue("tags"));
    }
    if (json.getValue("title") instanceof String) {
      obj.setTitle((String)json.getValue("title"));
    }
    if (json.getValue("type") instanceof String) {
      obj.setType((String)json.getValue("type"));
    }
    if (json.getValue("updatedOn") instanceof Number) {
      obj.setUpdatedOn(((Number)json.getValue("updatedOn")).longValue());
    }
  }

  public static void toJson(final Concert obj, final JsonObject json) {
    if (obj.getBeginOn() != null) {
      json.put("beginOn", obj.getBeginOn());
    }
    if (obj.getConcertTime() != null) {
      final JsonArray array = new JsonArray();
      obj.getConcertTime().forEach(item -> array.add(item.toJson()));
      json.put("concertTime", array);
    }
    if (obj.getContent() != null) {
      json.put("content", obj.getContent());
    }
    json.put("createdOn", obj.getCreatedOn());
    if (obj.getFaceValues() != null) {
      final JsonArray array = new JsonArray();
      obj.getFaceValues().forEach(item -> array.add(item.toJson()));
      json.put("faceValues", array);
    }
    if (obj.getId() != null) {
      json.put("id", obj.getId());
    }
    json.put("minPrice", obj.getMinPrice());
    if (obj.getPlace() != null) {
      json.put("place", obj.getPlace());
    }
    if (obj.getPoster() != null) {
      json.put("poster", obj.getPoster());
    }
    json.put("score", obj.getScore());
    if (obj.getSeatMapId() != null) {
      json.put("seatMapId", obj.getSeatMapId());
    }
    if (obj.getSeatType() != null) {
      json.put("seatType", obj.getSeatType());
    }
    if (obj.getSeats() != null) {
      json.put("seats", obj.getSeats());
    }
    if (obj.getShortDesc() != null) {
      json.put("shortDesc", obj.getShortDesc());
    }
    if (obj.getStatus() != null) {
      json.put("status", obj.getStatus());
    }
    if (obj.getTags() != null) {
      json.put("tags", obj.getTags());
    }
    if (obj.getTitle() != null) {
      json.put("title", obj.getTitle());
    }
    if (obj.getType() != null) {
      json.put("type", obj.getType());
    }
    json.put("updatedOn", obj.getUpdatedOn());
  }
}